package com.novoda.runbuddy.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;

import com.novoda.runbuddy.R;
import com.novoda.runbuddy.activity.stopwatch.RemoteStopClockProxy;
import com.novoda.runbuddy.controller.CalendarControllerImpl;
import com.novoda.runbuddy.controller.ICalendarController;
import com.novoda.runbuddy.controller.IOptionsMenu;
import com.novoda.runbuddy.controller.OptionsMenuImpl;

public class Calendar extends Activity {

	private ICalendarController	calendarController;
	private IOptionsMenu		optionsMenu;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.calendar);
		optionsMenu = new OptionsMenuImpl(this);

		calendarController = new CalendarControllerImpl();
		calendarController.createControls(this, this, (TextView) findViewById(R.id.cal_month),
				(Button) findViewById(R.id.btn_context_day), (Button) findViewById(R.id.btn_context_month),
				(Button) findViewById(R.id.btn_context_year), (Button) findViewById(R.id.btn_backPeriod),
				(Button) findViewById(R.id.btn_forwardPeriod));

		calendarController.createCalendar((TableLayout) findViewById(R.id.jogcalendar), (Button) findViewById(R.id.cal_00),
				(Button) findViewById(R.id.cal_01), (Button) findViewById(R.id.cal_02), (Button) findViewById(R.id.cal_03),
				(Button) findViewById(R.id.cal_04), (Button) findViewById(R.id.cal_05), (Button) findViewById(R.id.cal_06),
				(Button) findViewById(R.id.cal_10), (Button) findViewById(R.id.cal_11), (Button) findViewById(R.id.cal_12),
				(Button) findViewById(R.id.cal_13), (Button) findViewById(R.id.cal_14), (Button) findViewById(R.id.cal_15),
				(Button) findViewById(R.id.cal_16), (Button) findViewById(R.id.cal_20), (Button) findViewById(R.id.cal_21),
				(Button) findViewById(R.id.cal_22), (Button) findViewById(R.id.cal_23), (Button) findViewById(R.id.cal_24),
				(Button) findViewById(R.id.cal_25), (Button) findViewById(R.id.cal_26), (Button) findViewById(R.id.cal_30),
				(Button) findViewById(R.id.cal_31), (Button) findViewById(R.id.cal_32), (Button) findViewById(R.id.cal_33),
				(Button) findViewById(R.id.cal_34), (Button) findViewById(R.id.cal_35), (Button) findViewById(R.id.cal_36),
				(Button) findViewById(R.id.cal_40), (Button) findViewById(R.id.cal_41), (Button) findViewById(R.id.cal_42),
				(Button) findViewById(R.id.cal_43), (Button) findViewById(R.id.cal_44), (Button) findViewById(R.id.cal_45),
				(Button) findViewById(R.id.cal_46), (Button) findViewById(R.id.cal_50), (Button) findViewById(R.id.cal_51),
				(Button) findViewById(R.id.cal_52), (Button) findViewById(R.id.cal_53), (Button) findViewById(R.id.cal_54),
				(Button) findViewById(R.id.cal_55), (Button) findViewById(R.id.cal_56));

		startCalendarService();
	}

	@Override
	protected void onStart() {
		super.onStart();
		RemoteStopClockProxy.getInstance().registerListener(this);
	}
	
	@Override
	protected void onStop() {
		super.onStop();
		RemoteStopClockProxy.getInstance().unregisterListener(this);
	}

	public void startCalendarService() {
	}

	public void stopCalendarService() {
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		optionsMenu.selectItem(item);
		return super.onOptionsItemSelected(item);
	}

}
